local SkillIcon = class("SkillIcon")
local UIUtil = require("utils.UIUtil")

function SkillIcon:ctor()
    self._id = 0
end

function SkillIcon:awake()
    self._icon = self._imageIcon
    self._outline = self._imageBg.gameObject:GetComponent(typeof(CS.UnityEngine.UI.Outline))
    self._outline.enabled = false
    UIUtil.addButtonClick(self._imageIcon.transform, handler(self, self._onTouch))
end

function SkillIcon:updateUI(id)
    self._id = id
    self:_updateUI()
end

function SkillIcon:getId()
    return self._id
end

function SkillIcon:_updateUI()
    if self._id == 0 then
        return
    end
    local fightSkill = require("config.fight_skill").get(self._id)
    local configRes = require("config.skill_res").get(fightSkill.skill_res)
    local sprite = G_ResourceManager:loadSprite("SkillAtlas", configRes.icon)
    self._icon.sprite = sprite
end

function SkillIcon:setClickCallback(callback)
    self._clickCallback = callback
end

function SkillIcon:_onTouch()
    if self._clickCallback then
        self._clickCallback(self._id)
    else
        local pop = require("view.popup.PopupSkillTip").new(self._id)
    end
end

function SkillIcon:setVisible(visible)
    self.gameObject:SetActive(visible)
end

function SkillIcon:setSelected(selected)
    self._outline.enabled = selected
end

return SkillIcon
